CREATE TABLE [dbo].[DnnProduct_TabPermission]
(
[TabPermissionID] [int] NOT NULL IDENTITY(1, 1),
[TabID] [int] NOT NULL,
[PermissionID] [int] NOT NULL,
[AllowAccess] [bit] NOT NULL,
[RoleID] [int] NULL,
[UserID] [int] NULL,
[CreatedByUserID] [int] NULL,
[CreatedOnDate] [datetime] NULL,
[LastModifiedByUserID] [int] NULL,
[LastModifiedOnDate] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_TabPermission] ADD CONSTRAINT [PK_DnnProduct_TabPermission] PRIMARY KEY CLUSTERED  ([TabPermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_TabPermission] ADD CONSTRAINT [IX_DnnProduct_TabPermission] UNIQUE NONCLUSTERED  ([TabID], [PermissionID], [RoleID], [UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_TabPermission_Permission] ON [dbo].[DnnProduct_TabPermission] ([PermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_TabPermission_Roles] ON [dbo].[DnnProduct_TabPermission] ([RoleID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_TabPermission_Tabs] ON [dbo].[DnnProduct_TabPermission] ([TabID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_TabPermission_Users] ON [dbo].[DnnProduct_TabPermission] ([UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_TabPermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_TabPermission_DnnProduct_Permission] FOREIGN KEY ([PermissionID]) REFERENCES [dbo].[DnnProduct_Permission] ([PermissionID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_TabPermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_TabPermission_DnnProduct_Tabs] FOREIGN KEY ([TabID]) REFERENCES [dbo].[DnnProduct_Tabs] ([TabID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_TabPermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_TabPermission_DnnProduct_Users] FOREIGN KEY ([UserID]) REFERENCES [dbo].[DnnProduct_Users] ([UserID]) NOT FOR REPLICATION
GO
